﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="DatePickerSample.WindowsPhoneDatePickerPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DatePickerSample"
    xmlns:common="using:DatePickerSample.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:DatePicker="using:DatePicker"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">Windows Phone DatePicker sample</x:String>

        <Style TargetType="DatePicker:PickerSelectorItem" x:Key="PickerSelectorItemStyle">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Bottom" />
            <Setter Property="Template" >
                <Setter.Value>
                    <ControlTemplate TargetType="DatePicker:PickerSelectorItem">

                        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="Picker">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="InnerBorder">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="DarkGray"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerBorder">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="#1D1D1D"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="DarkGray"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Duration="0:0:0.200" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InnerBorder" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="UnFocused">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:0.200" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InnerBorder" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected" >
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="InnerBorder">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Blue"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerBorder">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Blue"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Duration="0:0:0.0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InnerBorder" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>

                            <Border BorderThickness="3,3,3,3" Margin="0,5,0,5" Padding="0" x:Name="InnerBorder" IsHitTestVisible="True">

                                <ContentPresenter x:Name="ContentPresenter"  
                                              Foreground="Transparent"
                                              ContentTemplate="{TemplateBinding ContentTemplate}" 
                                              Content="{TemplateBinding Content}" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Border>

                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="DatePickerStyle1" TargetType="DatePicker:DatePicker">
            <Setter Property="FontSize" Value="24"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DatePicker:DatePicker">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            
                        <Grid HorizontalAlignment="Stretch" Background="{TemplateBinding Background}"
                             
        					VerticalAlignment="Stretch"  Margin="5,0,5,0">

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto"  />
                                <ColumnDefinition Width="Auto"  />
                            </Grid.ColumnDefinitions>

                            <DatePicker:PickerSelector x:Name="PART_SecondarySelector" BorderThickness="1" 
        						Margin="5,0,5,0"
        						Grid.Column="0" 
        						VerticalAlignment="Bottom"
        						FontSize="{TemplateBinding FontSize}"
        						FontFamily="{TemplateBinding FontFamily}"
        						HorizontalContentAlignment="Left"
        						HorizontalAlignment="Left"
        						VerticalContentAlignment="Bottom" ItemContainerStyle="{StaticResource PickerSelectorItemStyle}">
                                <DatePicker:PickerSelector.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="5,0,0,5">
                                            <TextBlock Text="{Binding MonthNumber, Mode=TwoWay}" />
                                            <TextBlock FontSize="10"
        										Text="{Binding MonthName, Mode=TwoWay}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </DatePicker:PickerSelector.ItemTemplate>
                            </DatePicker:PickerSelector>
                            <DatePicker:PickerSelector x:Name="PART_TertiarySelector" BorderThickness="1" Grid.Column="1"
        						Margin="5,0,5,0" ItemContainerStyle="{StaticResource PickerSelectorItemStyle}"
        						FontSize="{TemplateBinding FontSize}"
        						FontFamily="{TemplateBinding FontFamily}">
                                <DatePicker:PickerSelector.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="5,0,0,5">
                                            <TextBlock Text="{Binding DayNumber, Mode=TwoWay}" />
                                            <TextBlock FontSize="10"
        										Text="{Binding DayName, Mode=TwoWay}" />

                                        </StackPanel>
                                    </DataTemplate>
                                </DatePicker:PickerSelector.ItemTemplate>
                            </DatePicker:PickerSelector>
                            <DatePicker:PickerSelector x:Name="PART_PrimarySelector" BorderThickness="1" Grid.Column="2"
        						Margin="5,0,5,0" ItemContainerStyle="{StaticResource PickerSelectorItemStyle}"
        						FontSize="{TemplateBinding FontSize}"
        						FontFamily="{TemplateBinding FontFamily}">
                                <DatePicker:PickerSelector.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="5,0,0,5">
                                            <TextBlock Text="{Binding YearNumber, Mode=TwoWay}" />
                                            <TextBlock FontSize="10" Text=" " />

                                        </StackPanel>
                                    </DataTemplate>
                                </DatePicker:PickerSelector.ItemTemplate>
                            </DatePicker:PickerSelector>
                        </Grid>
                        </Border>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>



        <DatePicker:DatePicker BorderBrush="White" BorderThickness="1" HorizontalAlignment="Left" Margin="550,45,0,0" Grid.Row="1" 
                                VerticalAlignment="Top" Height="495" Width="320" Value="{Binding CurrentDateTime, Mode=TwoWay}" 
                                Style="{StaticResource DatePickerStyle1}"/>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
